/**
 *	The NeuroCoSA Toolkit
 *	Copyright (C) 2003-6 Stuart Meikle.
 *
 *	This is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 * @author	Stuart Meikle
 * @version	2006-halloween(mk2)
 * @license	LGPL
 */
package org.stumeikle.NeuroCoSA.AutoCluster;

/* Comments:
 * 20060125	stumeikle	new classes to abstract away the data type.
 *				used by the STLTMemory
*/

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import javax.swing.event.*;

public	class		NScalar implements NMeasurable, Cloneable
{
    double	v;

    public NScalar() {}
    public NScalar(double d)
    { v=d; }

    // Interface implentation --------------------------------------------
    public	double		distanceTo( NMeasurable p )
    {
	return distanceTo( (NScalar) p );
    }
    
    public	double	        distanceSquaredTo( NMeasurable p )
    {
    	return distanceSquaredTo( (NScalar) p );
    }
    
    public	void		add( NMeasurable p )
    {
    	add((NScalar)p);
    	return;
    }
    
    public	void		subtract( NMeasurable p )
    {
    	subtract((NScalar)p);
    	return;
    }
    
    public	double		magnitude()
    {
    	return v;
    }
    
    public	double		dotProduct(NMeasurable p)
    {
    	return dotProduct((NScalar)p);
    }
    
    public	NMeasurable	createNewZero()
    {
    	//create a new data type , set to zero and return 
    	NScalar		s = new NScalar();
    	
    	s.v =0.0;
	return	(NMeasurable)s;
    }

    
    public	void		divideByScalar( double d )
    {
	if (d>0.0001 || d< -0.001)
	{
	    v/=d;
	}
    }
    
    public	void		multiplyByScalar( double d )
    {
    	v*=d;
    }

    // internal methods -------------------------------------------------
    public	double		distanceTo( NScalar p )
    {
        double	dx;
        
        dx = p.v - v;
        
        return Math.sqrt( dx*dx );
    }
    
    public	double		distanceSquaredTo( NScalar p )
    {
        double	dx;
        
        dx = p.v - v;
        
        return dx*dx;
    }
    
    public	void		add( NScalar p )
    {
    	v += p.v;
    }    
    
    public	void		subtract( NScalar p )
    {
    	v -= p.v;
    }    

    public	double		dotProduct( NScalar p )
    {
        return	v * p.v; 
    }
    
    public	double		getValue() 
    { return v; }
    
    public	void		setValue( double d )
    { v = d; }
    
    public	NMeasurable	createCopy()
    {
    	try {  return (NMeasurable) this.clone(); }
    	catch( Exception e )
    	{ return null; }
    }
    
    public	Object		clone()
    {
    	try{  return super.clone();}
    	catch(Exception e)
    	{return null;}
    }
}
